Edited March, 1994 by Roland Pesch (pesch@cygnus.com
)
Copyright © 1992, 1993, 1994 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As you may remember, GNU C++ was the first native-code C++ compiler available under Unix (December 1987). In November 1988, it was judged superior to the AT&T compiler in a Unix World review. In 1990 it won a Sun Observer “Best-Of” award. But now, with new requirements coming out of the ANSI C++ committee and a growing backlog of bugs, it’s clear that GNU C++ needs an overhaul.
The C++ language has been under development since 1982. It has evolved significantly since its original incarnation (C with Classes), addressing many commercial needs and incorporating many lessons learned as more and more people started using “object-oriented” programming techniques. In 1989, the first X3J16 committee meeting was held in Washington DC; in the interest of users, C++ was going to be standardized.
As C++ has become more popular, more demands have been placed on its compilers. Some compilers are up to the demands, others are not. GNU C++ was used to prototype several features which have since been incorporated into the standard, most notably exception handling. While GNU C++ has been an excellent experimental vehicle, it did not have the resources that AT&T, Borland, or Microsoft have at their disposal.
We believe that GNU C++ is an important compiler, providing users with many of the features that have made GNU C so popular: fast compilation, good error messages, innovative features, and full sources that may be freely redistributed. The purpose of this overhaul, dubbed the GNU C++ Renovation Project, is to take advantage of the functionality that GNU C++ offers today, to strengthen its base technology, and put it in a position to remain—as other GNU software currently is—the technical leader in the field.
This release represents the latest phase of work in strengthening the compiler on a variety of points. It includes many months of work concentrated on fixing many of the more egregious bugs that presented themselves in the compiler recently. In the coming months, we hope to continue expanding and enhancing the quality and dependability of the industry’s only freely redistributable C++ compiler.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The GNU C++ compiler continues to improve and change. A major goal of our work has been to continue to bring the compiler into compliance with the draft ANSI C++ standard, and with The Annotated C++ Reference Manual (the ARM). This section outlines most of the user-noticeable changes that might be encountered during the normal course of use.
2.1 Summary of Changes in Phase 1.3 | ||
2.2 Major Changes | ||
2.3 New features | ||
2.4 Enhancements and bug fixes | ||
2.5 Problems with debugging |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The bulk of this note discusses the cumulative effects of the GNU C++ Renovation Project to date. The work during its most recent phase (1.3) had these major effects:
g++
is now the faster compiled
version, rather than a shell script.
mutable
is supported.
Much of the work in Phase 1.3 went to elimination of known bugs, as well as the major items above.
During the span of Phase 1.3, there were also two changes associated with the compiler that, while not specifically part of the C++ Renovation project, may be of interest:
gcov
, a code coverage tool for GNU CC, is now available
from Cygnus Support. (gcov
is free software, but the FSF has not
yet accepted it.) See gcov
: a Test Coverage Program in Using GNU CC, for more information (in Cygnus releases of
that manual).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This release includes four wholesale rewrites of certain areas of compiler functionality:
g++
driver.
A new binary g++
compiler driver replaces the shell script.
The new driver executes faster.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You do not need to use the ‘-fexternal-templates’ option when compiling a file that does not define and instantiate templates used in other files, even if those files are compiled with ‘-fexternal-templates’. The only side effect is an increase in object size for each file that was compiled without ‘-fexternal-templates’.
When your code is compiled with ‘-fexternal-templates’, all
template instantiations are external; this requires that the templates
be under the control of ‘#pragma interface’ and ‘#pragma
implementation’. All instantiations that will be needed should be in
the implementation file; you can do this with a typedef
that
references the instantiation needed. Conversely, when you compile using
the option ‘-fno-external-templates’, all template instantiations are
explicitly internal.
‘-fexternal-templates’ also allows you to finally separate class template function definitions from their declarations, thus speeding up compilation times for every file that includes the template declaration. Now you can have tens or even hundreds of lines in template declarations, and thousands or tens of thousands of lines in template definitions, with the definitions only going through the compiler once instead of once for each source file. It is important to note that you must remember to externally instantiate all templates that are used from template declarations in interface files. If you forget to do this, unresolved externals will occur.
In the example below, the object file generated (‘example.o’) will contain the global instantiation for ‘Stack<int>’. If other types of ‘Stack’ are needed, they can be added to ‘example.cc’ or placed in a new file, in the same spirit as ‘example.cc’.
foo.h
:
#pragma interface "foo.h" template<class T> class Stack { static int statc; static T statc2; Stack() { } virtual ~Stack() { } int bar(); };
example.cc
:
#pragma implementation "foo.h" #include "foo.h" typedef Stack<int> t; int Stack<int>::statc; int Stack<int>::statc2; int Stack<int>::bar() { }
Note that using ‘-fexternal-templates’ does not reduce memory usage from completely different instantiations (‘Stack<Name>’ vs. ‘Stack<Net_Connection>’), but only collapses different occurrences of ‘Stack<Name>’ so that only one ‘Stack<Name>’ is generated.
‘-falt-external-templates’ selects a slight variation in the semantics described above (incidentally, you need not specify both options; ‘-falt-external-templates’ implies ‘-fexternal-templates’).
With ‘-fexternal-templates’, the compiler emits a definition in the implementation file that includes the header definition, even if instantiation is triggered from a different implementation file (e.g. with a template that uses another template).
With ‘-falt-external-templates’, the definition always goes in the implementation file that triggers instantiation.
For instance, with these two header files—
‘a.h’: #pragma interface template <class T> class A { … }; ‘b.h’: #pragma interface class B { … }; void f (A<B>);
Under ‘-fexternal-templates’, the definition of ‘A<B>’ ends up in the implementation file that includes ‘a.h’. Under ‘-falt-external-templates’, the same definition ends up in the implementation file that includes ‘b.h’.
To instantiate a class template explicitly, write ‘template class name<paramvals>’, where paramvals is a list of values for the template parameters. For example, you might write
template class A<int>
Similarly, to instantiate a function template explicitly, write ‘template fnsign’ where fnsign is the particular function signature you need. For example, you might write
template void foo (int, int)
This syntax for explicit template instantiation agrees with recent extensions to the draft ANSI standard.
return
in a
non-void
function (one returning a value); declaring a local
variable that shadows a parameter (e.g., the function takes an argument
‘a’, and has a local variable ‘a’); and use of the ‘asm’
keyword. Finally, the compiler by default now issues a warning when
converting from an int
to an enumerated type. This is likely to
cause many new warnings in code that hadn’t triggered them before. For
example, when you compile this code,
enum boolean { false, true }; void f () { boolean x; x = 1; //assigning anint
to anenum
now triggers a warning }
you should see the warning “anachronistic conversion from integer
type to enumeral type `boolean'
”. Instead of assigning the value 1,
assign the original enumerated value ‘true’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
list
, the following now works:
struct glyph { … struct stroke { … }; list<stroke> l; … }
list
class
in terms of a pointer to a function like this:
list<int (*)(int, void *)> fnlist;
mutable
.
GNU C++ supports it. Use mutable
to specify that some
particular members of a const
class are not constant. For
example, you can use this to include a cache in a data structure that
otherwise represents a read-only database.
template <class T, T t> class A { … };
int
do not actually do anything, but their existence provides a
level of generality that permits smooth template expansion in more
cases.)
t.C:1: warning: `catch', `throw', and `try' are all C++ reserved words
static
no longer
receive a this
pointer.
unsigned
.
unsigned
bitfields are now promoted to signed int
if the
field isn’t as wide as an int
.
class foo { public: operator ++ (); operator ++ (int); operator -- (); operator -- (int); }; void f (foo *f) { f++; // callf->operator++(int)
++f; // callf->operator++()
f--; // callf->operator++(int)
--f; // callf->operator++()
}
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Two problems remain with regard to debugging:
gdb
coredump under certain circumstances. This
problem is not host-specific.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The overall goal for the second phase of the GNU C++ Renovation Project is to bring GNU C++ to a new level of reliability, quality, and competitiveness. As particular elements of this strategy, we intend to:
As always, we encourage you to make suggestions and ask questions about GNU C++ as a whole, so we can be sure that the end of this project will bring a compiler that everyone will find essential for C++ and will meet the needs of the world’s C++ community.
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 16, 2022 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on April 16, 2022 using texi2html 5.0.